﻿using System;
using NumericalMatrix.Interfaces;
using NumericalMatrix.Services;
using NumericalMatrix.GenericInterfaces;
using NumericalMatrix.Implementation;

namespace NumericalMatrix
{
    public class Matrix : IMatrix<double>
    {
        #region Fields and Constants

        private double[,] m;

        private int width;

        private int height;

        private IGroupOperations<double> groupOperations;

        private ILUBlock<double> lUBlock;

        #endregion

        #region Constructors

        public Matrix()
        {
            groupOperations = new DoubleOperations();
        }

        public Matrix(int rowCount, int columnCount)
            : this()
        {
            width = columnCount;
            height = rowCount;
        }

        #endregion

        #region IMatrix implementation

        public int Width
        {
            get { return width; }
        }

        public int Height
        {
            get { return height; }
        }

        public double this[int i, int j]
        {
            set
            { 
                m[i, j] = value;
            }
            get
            {
                return m[i, j];
            }
        }

        public IGroupOperations<double> GroupOperations
        {
            get { return groupOperations; }
        }

        public IMatrix<GroupOperators> CreateInstance(int height, int width)
        {
            throw new NotImplementedException();
        }

        public IMatrix<double> CreateDoubleInstance(int height, int width)
        {
            throw new NotImplementedException();
        }
    
        #endregion
        
        public ILUBlock<double> LUBlock
        {
            get
            {
                if (lUBlock == null)
                {
                    lUBlock = new LUBlock<double>(this);// as IMatrix<double>);
                }
                return lUBlock;
            }
        }

    }
}
